package com.clean.cleantotal.compores.clean

import android.view.View
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import com.clean.cleantotal.R
import com.clean.cleantotal.base.BaseGroupActivity
import com.clean.cleantotal.databinding.ActivityNewScanResultBinding
import com.clean.cleantotal.utils.FormatterSize
import com.clean.cleantotal.utils.Utils
import com.drake.brv.utils.bindingAdapter

class NewScanResultActivity : BaseGroupActivity<ActivityNewScanResultBinding>() {
    override val viewBinding: ActivityNewScanResultBinding
        get() = ActivityNewScanResultBinding.inflate(layoutInflater)

    override fun initView() {
        super.initView()
        mBinding.back.setOnClickListener { onBackPressed() }
        mBinding.includedLayout.yellowYuan.isVisible = true
        mBinding.tvClean.text =
            "Clean (${FormatterSize.formatFileSize(this, selectList.sumOf { it.size })})"
        mBinding.includedLayout.ivFinish.isVisible = false
        mBinding.includedLayout.tvTitle.text = "Found"

        mBinding.includedLayout.tvContent.text =
            "Your phone has garbage and it is \n recommended to clean it up！"

        initRecyclerViewData(Utils.cleanGroups)

        val size = FormatterSize.formatFileSizeSplit(this, totalSize)
        mBinding.includedLayout.tvSize.text = size.first()
        mBinding.includedLayout.tvUnit.text = size.last()
    }

    override fun isLargeScan(): Boolean {
        return false
    }

    override fun initGroupRecyclerView(): RecyclerView {
        return mBinding.recyclerView
    }

    override fun allSelectView(): View {
        return mBinding.allLayout
    }

    override fun clickCleanView(): View {
        return mBinding.tvClean
    }

    override fun updateUi() {
        isAllSelect = selectList.size == totalCount
        mBinding.ivAll.setImageResource(if (isAllSelect) R.mipmap.green_clean_hospital else R.mipmap.green_clean_careful)
        mBinding.tvClean.text =
            "Clean (${FormatterSize.formatFileSize(this, selectList.sumOf { it.size })})"
        mBinding.recyclerView.bindingAdapter.notifyDataSetChanged()
    }
}